use "$data\NPL_hh_data.dta", clear

eststo clear
* Total earnings regressions
sum laborInc if covid==0 & inrange(round,3,7)
local pre_mean  = `r(mean)'
eststo: reg laborInc treat covid highRemit i.harvest if inrange(round,3,7), vce(cluster hhno)
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'
eststo: areg laborInc treat covid  i.harvest if inrange(round,3,7), a(hhno) vce(cluster hhno)
	estadd local fe_hh X
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'

* Remittance earnings regressions
sum remit if covid==0 & inrange(round,3,7)
local pre_mean  = `r(mean)'
eststo: reg remit treat covid highRemit i.harvest if inrange(round,3,7), vce(cluster hhno)
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'
eststo: areg remit treat covid  i.harvest if inrange(round,3,7), a(hhno) vce(cluster hhno)
	estadd local fe_hh X
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'

* Food security regressions
sum remit if covid==0 & inrange(round,3,7)
eststo: reg FoodIns treat covid highRemit i.month if round>5, vce(cluster hhno)
	estadd local fe_t Month
	estadd scalar prem = `pre_mean'
eststo: areg FoodIns treat covid i.month if round>5, a(hhno) vce(cluster hhno)
	estadd local fe_hh X
	estadd local fe_t Month
	estadd scalar prem = `pre_mean'

local col1 " Outcome: & \multicolumn{2}{c}{Labor Income} & \multicolumn{2}{c}{Remittance Income} & \multicolumn{2}{c}{Food Insecurity} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7}"
local col2 " Comparison Period: & \multicolumn{2}{c}{Sep--Dec 2019} & \multicolumn{2}{c}{Sep--Dec 2019} & \multicolumn{2}{c}{Typical Year} \\"
local col3 " Source: & \multicolumn{2}{c}{Survey} & \multicolumn{2}{c}{Survey} & \multicolumn{2}{c}{Recall} \\ \midrule"
esttab using "$tables/Table_S8.tex", keep(treat covid highRemit) ///
	replace se tex label  mlabels(none) nonotes nonumbers nostar b(3) /// starlevels(* 0.1 ** 0.05 *** 0.01)
	stats(fe_hh fe_t prem r2 N, fmt(0 0 2 2 0) labels("HH FEs" "Time FEs" "Prior Mean" "R-Squared" "Observations")) ///
	posthead(`col1' `col2' `col3')
	
eststo clear
foreach y of varlist remit wageAgIncMonth wageNonIncMonth miscInc {

* Earnings decomposition regressions
sum `y' if covid==0 & inrange(round,3,7)
local pre_mean  = `r(mean)'
eststo: reg `y' treat covid highRemit i.harvest if inrange(round,3,7), vce(cluster hhno)
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'
eststo: areg `y' treat covid  i.harvest if inrange(round,3,7), a(hhno) vce(cluster hhno)
	estadd local fe_hh X
	estadd local fe_t Season
	estadd scalar prem = `pre_mean'
}

local col1 " Outcome: & \multicolumn{2}{c}{Remittance} & \multicolumn{2}{c}{Ag. Wage} & \multicolumn{2}{c}{NonAg. Wage} & \multicolumn{2}{c}{Misc.} \\  \midrule"
esttab using "$tables/Table_S9.tex", keep(treat covid highRemit) ///
	replace se tex label  mlabels(none) nonotes nonumbers nostar b(1) /// starlevels(* 0.1 ** 0.05 *** 0.01)
	stats(fe_hh fe_t prem r2 N, fmt(0 0 2 2 0) labels("HH FEs" "Time FEs" "Prior Mean" "R-Squared" "Observations")) ///
	posthead(`col1' `col2' `col3')


use "$data\NLS_hh_data.dta", clear

eststo clear
* Compare to prior years
sum hungry if covid==0 & series<2
local pre_mean  = `r(mean)'
eststo: areg hungry treat covid migr_any if series<2 | covid==1 [aw=wgt_c], a(month) vce(cluster hhid)
	estadd local fe_m X
	estadd scalar prem = `pre_mean'
eststo: areg hungry treat covid i.month if series<2 | covid==1 [aw=wgt_c], a(hhid) vce(cluster hhid)
	estadd local fe_m X
	estadd local fe_hh X
	estadd scalar prem = `pre_mean'

* Compare to Jan/Feb 2020
sum hungry if covid==0 & series==2
local pre_mean  = `r(mean)'
eststo: reg hungry treat covid migr_any if series==2 [aw=wgt_c], vce(cluster hhid)
	estadd scalar prem = `pre_mean'
eststo: areg hungry treat covid if series==2 [aw=wgt_c], a(hhid) vce(cluster hhid)
	estadd local fe_hh X
	estadd scalar prem = `pre_mean'

local col1 " Outcome: & \multicolumn{4}{c}{HH Food Insecurity} \\ \cmidrule(lr){2-5}"
local col2 " Comparison Period: & \multicolumn{2}{c}{2017--2019} & \multicolumn{2}{c}{Jan--Feb 2020} \\"
local col3 " Source: & \multicolumn{2}{c}{Survey} & \multicolumn{2}{c}{Recall} \\ \midrule"
esttab using "$tables/Table_S10.tex", keep(treat covid migr_any) ///
	replace se tex label  mlabels(none) nonotes nonumbers nostar b(3) /// starlevels(* 0.1 ** 0.05 *** 0.01)
	stats(fe_hh fe_m prem r2 N, fmt(0 0 2 2 0) labels("HH FEs" "Month FEs" "Prior Mean" "R-Squared" "Observations")) ///
	posthead(`col1' `col2' `col3')
	

use "$data\URB_indiv_long.dta", clear

label var treat "Migrant $\times$ COVID-19"
label var covid "COVID-19"
label var migr "Migrant"

eststo clear
* Compare to Oct 2018-Jan 2019
sum earn_month if covid==0 & round!=5
local pre_mean  = `r(mean)'
eststo: areg earn_month treat covid migr if round!=5, a(market_id) vce(cluster uidno)
	estadd local fe_m X
	estadd scalar prem = `pre_mean'
eststo: areg earn_month treat covid if round!=5, a( uidno) vce(cluster uidno)
	estadd local fe_hh X
	estadd scalar prem = `pre_mean'

* Compare to May 2019
sum earn_month if covid==0 & round==5
local pre_mean  = `r(mean)'
eststo: areg earn_month treat covid migr if round>=5, a(market_id) vce(cluster uidno)
	estadd local fe_m X
	estadd scalar prem = `pre_mean'
eststo: areg earn_month treat covid if round>=5, a( uidno) vce(cluster uidno)
	estadd local fe_hh X
	estadd scalar prem = `pre_mean'


local col1 " Outcome: & \multicolumn{4}{c}{Monthly Earnings} \\ \cmidrule(lr){2-5}"
local col2 " Comparison Period: & \multicolumn{2}{c}{Oct 2018--Jan 2019} & \multicolumn{2}{c}{May 2019} \\"
local col3 " Source: & \multicolumn{2}{c}{Survey} & \multicolumn{2}{c}{Recall} \\ \midrule"
esttab using "$tables/Table_S11.tex", keep(treat covid migr) ///
	replace se tex label  mlabels(none) nonotes nonumbers nostar b(3) /// starlevels(* 0.1 ** 0.05 *** 0.01)
	stats(fe_m fe_hh prem r2 N, fmt(0 0 2 2 0) labels("Market FEs" "Worker FEs" "R-Squared" "Observations")) ///
	posthead(`col1' `col2' `col3')
